﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Repository;
using FRL.DebtChased.Silverlight.Library;
using FRL.DebtChased.Silverlight.Library.RichContentService;

namespace FRL.DebtChased.ClientEditor
{

	/// <summary>
	/// Declaration of CachedData class
	/// Singleton pattern class for storing supporting data
	/// </summary>
	public class CachedData : CachedDataBase
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		public static CachedData Singleton
		{
			get { return m_SingletonBase as CachedData; }
		}

		private ObservableCollection<string> m_ClientActivities = null;
		public ObservableCollection<string> ClientActivities
		{
			get { return m_ClientActivities; }
		}

		private Dictionary<int, string> m_FinanceTeams = null;
		public Dictionary<int,string> FinanceTeams
		{
			get { return m_FinanceTeams; }
		}

		/////////////////////////////////////////////////////////////
		// Construction

		static CachedData()
		{

			// Create the single instance
			new CachedData();

		}

		/////////////////////////////////////////////////////////////
		// Operations

		public void AddIncoming(ClientEditorSupportData supportData)
		{

			// Process data returned from server

			// Call base-class function
			base.AddIncoming(
				supportData.CurrentUser,
				supportData.CountryMap,
				supportData.ContactPositions,
				supportData.ContactTitles,
				supportData.ContactCounties,
				supportData.BankNames
			);

			// Get client activites
			m_ClientActivities = supportData.ClientActivities;

			// Update finance-team map
			m_FinanceTeams = new Dictionary<int,string>();
			foreach(var diLoop in supportData.FinanceTeamMap)
				m_FinanceTeams.Add( diLoop.Key, diLoop.Value );
				
		}

		/////////////////////////////////////////////////////////////
		// Static Operations - Fake data used during testing

#if USEFAKEDATA
		public static ClientEditorSupportData GetDummySupportingData()
		{

			// Declare return variable
			ClientEditorSupportData Ftmp = new ClientEditorSupportData();
			Ftmp.CurrentUser = CachedDataBase.GetDummaryUserSessionTransport(false);

			// Add supporting object lists
			Ftmp.CountryMap = CachedDataBase.GetDummyCountryMap();
			Ftmp.ContactCounties = CachedDataBase.GetDummyContactCounties();
			Ftmp.ContactPositions = CachedDataBase.GetDummyContactPositions();
			Ftmp.ContactTitles = CachedDataBase.GetDummyContactTitles();

			// Client activites
			Ftmp.ClientActivities = new ObservableCollection<string>();
			Ftmp.ClientActivities.Add("Builder");
			Ftmp.ClientActivities.Add("Baker");

			// Finance-team map
			Ftmp.FinanceTeamMap = new Dictionary<int, string>();
			Ftmp.FinanceTeamMap.Add(1, "Team 1");
			Ftmp.FinanceTeamMap.Add(2, "Team 2");
			Ftmp.FinanceTeamMap.Add(3, "Team 3");

			// Return variable
			return Ftmp;

		}
#endif // #if USEFAKEDATA

	}

}
